package com.anjufang.service.user.impl;

import com.alibaba.fastjson.JSON;
import com.anjufang.service.user.UserCacheService;
import com.anjufang.utils.cache.CacheData;
import com.anjufang.utils.cache.CacheKey;
import com.anjufang.utils.cache.RedisGroups;
import com.anjufang.utils.cache.RedisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class UserCacheServiceImpl implements UserCacheService {

    protected Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public int getUserNo(int type) {
        CacheKey key = new CacheKey(type == 0 ? RedisGroups.CACHE_USER_NO_TWO_KEY : RedisGroups.CACHE_USER_NO_ONE_KEY);
        CacheData data = RedisUtil.rpop(key);
        logger.info("UserCacheServiceImpl.getUserNo, redis获取用户随机抽签编号，编号：{}", JSON.toJSONString(data));
        if (null != data) {
            return data.getData();
        }
        return 0;
    }
}
